package com.kxn.multi.module.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.kxn.multi.module.common.pojo.ApiResult;
import com.kxn.multi.module.service.entity.AdminRolePermission;
import com.kxn.multi.module.service.service.AdminRolePermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
* <p>
* 角色权限表 前端控制器
* </p>
*
* @author kxn
* @since 2023-04-18
*/
@Api(tags = "角色权限表")
@RestController
@RequestMapping("/admin/adminRolePermission")
public class AdminRolePermissionController {

    @Resource
    private AdminRolePermissionService adminRolePermissionService;

    @ApiOperation(value = "角色权限表分页列表", response = AdminRolePermission.class)
    @ApiImplicitParams({
    @ApiImplicitParam(name = "pageSize", value = "页面", dataType = "Integer"),
    @ApiImplicitParam(name = "pageNum", value = "页面数据量", dataType = "Integer"),
    @ApiImplicitParam(name = "sort", value = "排序方式排序[true:正序; false:倒序]", dataType = "Boolean"),
    @ApiImplicitParam(name = "sortName", value = "排序字段,参照返回字段", dataType = "String")})
    @PostMapping(value = "/page")
    public ApiResult list(@Valid @RequestBody AdminRolePermission param) {
        IPage<AdminRolePermission> data  = adminRolePermissionService.page(param);
        return ApiResult.success(data);
    }

    @ApiOperation(value = "角色权限表详情", response = AdminRolePermission.class)
    @GetMapping(value = "/{id}")
    public ApiResult detail(@PathVariable Long id) {
        AdminRolePermission data = adminRolePermissionService.detail(id);
        return ApiResult.success(data);
    }

    @ApiOperation(value = "角色权限表新增")
    @PostMapping(value = "/create")
    public ApiResult create(@Valid @RequestBody AdminRolePermission param) {
        adminRolePermissionService.create(param);
        return ApiResult.success(param);
    }

    @ApiOperation(value = "角色权限表修改")
    @PostMapping("/update/{id}")
    public ApiResult update(@PathVariable Long id, @Valid @RequestBody AdminRolePermission param) {
        adminRolePermissionService.updateById(id, param);
        return ApiResult.success(param);
    }

    @ApiOperation(value = "角色权限表删除单个条目")
    @GetMapping(value = "/delete/{id}")
    public ApiResult delete(@PathVariable Long id) {
        adminRolePermissionService.delete(id);
        return ApiResult.success();
    }

    @ApiOperation(value = "角色权限表删除多个条目")
    @PostMapping(value = "/batchDel")
    public  Object batchDel(@Valid @RequestBody List<Long> ids) {
        adminRolePermissionService.batchDelete(ids);
        return ApiResult.success();
    }

}
